package Engine;

public class Vector3D {

	public float x,y,z;
	
	public Vector3D(){
		x = 0; y = 0; z = 0;
	}
	
	public Vector3D(float x,float y,float z){
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Vector3D(Vector3D v){
		x = v.x;
		y = v.y;
		z = v.z;
	}

	Vector3D multiply(Vector3D V2){
		return new Vector3D (x * V2.x,  y * V2.y,  z * V2.z);
	}	

	public float Dot(Vector3D v1){
		return v1.x*x + v1.y*y + v1.z*z;
	}

	Vector3D CrossProduct( Vector3D V2 ){
		return new Vector3D(
				y * V2.z  -  z * V2.y,
				z * V2.x  -  x * V2.z,
				x * V2.y  -  y * V2.x 	);
	}

	Vector3D RotByMatrix( float m[] ){
		return new Vector3D( 
				x*m[0] + y*m[4] + z*m[8],
				x*m[1] + y*m[5] + z*m[9],
				x*m[2] + y*m[6] + z*m[10] );
	}

	float Magnitude(){
		return (float)Math.sqrt( x*x + y*y + z*z );
	}

	float Distance(Vector3D V1){
		return multiply(V1).Magnitude();
	}
	
	void Normalize(){
		float fMag = ( x*x + y*y + z*z );
		if (fMag == 0) {return;}

		float fMult = (float)(1.0f/Math.sqrt(fMag));            
		x *= fMult;
		y *= fMult;
		z *= fMult;
	}
}
